﻿using System;
using System.Collections.Generic;
using Wintellect.PowerCollections;
using System.Collections;

namespace Ex5.PriorityQueue
{
    class PriorityQueue<T> : IEnumerable<T>
    {
        private OrderedBag<T> bag;

        public PriorityQueue()
        {
            bag = new OrderedBag<T>();
        }

        public void Enqueue(T element)
        {
            bag.Add(element);
        }

        public T Dequeue()
        {
            var element = bag.GetFirst();
            bag.RemoveFirst();
            return element;
        }

        public int Count
        {
            get { return bag.Count; }
            private set { }
        }

        public T this[int index]
        {
            get
            {
                if (index >= 0 && index < this.bag.Count)
                {
                    return this.bag[index];
                }

                throw new IndexOutOfRangeException("Wanted element index is out of range!");
            }
        }


        IEnumerator<T> IEnumerable<T>.GetEnumerator()
        {
            return this.bag.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.bag.GetEnumerator();
        }
    }
}
